import Vue from "vue";
import store from '@/store'
let win = null
function openWindown(url,name,attrs){
  if(win){
    //console.log("%c Line:4 🍺 win", "color:#2eafb0", win);
    if(win.closed){
      win = window.open(url,name,attrs );
    }else{
      win.focus()
      let str1 = ''
      let obj = {}
      if(url.indexOf('?')>-1){
        str1 = url.split('?')[1]
        let arr = str1.split('&')
        if(arr&&arr.length){
          arr.forEach(r=>{
           let arr2 = r.split('=')
            obj[arr2[0]] = arr2[1]
          })
        }
      }
      // 重新打开时告诉子页面联系人信息
      win.postMessage(obj,Vue.prototype.IMhost)
    }
  }else{
    win = window.open(url,name,attrs );
  }
}
function close(){
  win
  //console.log("%c Line:31 🍣 win", "color:#4fff4B", win);
  if(win&&!win.closed){
    win.close()
  }
}
function postData(data){
  //console.log("发送给子窗口未读数据%c Line:38 🥚 data", "color:#465975", data);
  // 
  win.postMessage(data,Vue.prototype.IMhost)
}
function setWin(value){
  win = value
}
let obj = {
  openWindown,setWin,close,postData
};
export default obj;